import { defineConfig,loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import createVitePlugins from "./vite/plugin/index.js"

// https://vite.dev/config/
export default defineConfig(({mode, command})=>{
	const env = loadEnv(mode, process.cwd())
	return {
		plugins: createVitePlugins(env, command == 'build'),
		resolve: {
			alias: {
				'~': path.resolve(__dirname, './'),//~ 设置路径
				"@": path.resolve(__dirname, './src')//@ 表示 src
			},
			extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
		},
		build: {
			//打包时候的配置
			terserOptions: {
				compress: {
					drop_console: true,
					drop_debugger: true
				}
			}
		},
		server: {
			port: 5173,
			open: false,
			proxy: {
				'/api': {
					target: 'http://localhost:8080',
					changeOrigin: true,
					rewrite: (p) => p.replace(/^\/api/, '')
				}
			}
		},
	}
})
